﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Data;
/// <summary>
/// Summary description for TestUser
/// </summary>
public class TestUser
{
    public int kiemtra(string username, string pass)
    {
        SqlConnection conn = new SqlConnection
        (ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
        byte[] hashedBytes;
        UTF8Encoding encoder = new UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(pass));
        SqlCommand Cmd = new SqlCommand
        (" Select * from tblUser where userName=@id and password=@pass", conn);
        Cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.NVarChar, 500));
        Cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 500));
        Cmd.Parameters["@id"].Value = username;
        Cmd.Parameters["@pass"].Value = encoder.GetString(hashedBytes);
        if (Cmd.ExecuteReader().HasRows)
        {
            return 1;
        }
        else
        {
            return 0;
        }
	}
}
